from string import upper
import re
from sys import stdin

SCORES = {'A':1, 'E':1, 'I':1, 'L':1, 'N':1, 'O':1, 'R':1, 'S':1, 'T':1, 'U':1,
          'D':2, 'G':2, 'B':3, 'C':3, 'M':3, 'P':3, 'F':4, 'H':4, 'V':4, 'W':4,
          'Y':4, 'K':5, 'J':8, 'X':8, 'Q':10, 'Z':10}

def read_dictionary_from_file():
    
    k, n, i = 0, 0, 0
    dictionary = []
    scores = {}
    def word_score(word):
        score = 0
        for i in range(len(word)):
            score += SCORES[word[i]]
        return score
    
    while True:
        line = raw_input()
        if i == 0:
            k = int(line)
        elif i == 1:
            n = int(line)
        elif len(line) == k:
            dictionary.append(line)
            scores[line] = word_score(line)
        i += 1
        if i == n + 2:
            break
    
    return k, dictionary, scores

def compute_neighbours_list(dictionary):
    neighbours = {}
   
    def is1CharDiff(word1, word2):
        diff_count = 0
        for l1, l2 in zip(word1, word2):
            if l1 != l2:
                diff_count += 1
                if diff_count > 1:
                    return False
        return True                       

        
    for i in range(len(dictionary)):
        
        for j in range(i + 1, len(dictionary)):
            if is1CharDiff(dictionary[i],
                                        dictionary[j]):
                if dictionary[i] in neighbours:
                    neighbours[dictionary[i]].append(dictionary[j])
                else:
                    neighbours[dictionary[i]] = [dictionary[j]]
                
                if dictionary[j] in neighbours:
                    neighbours[dictionary[j]].append(dictionary[i])
                else:
                    neighbours[dictionary[j]] = [dictionary[i]]
        if not dictionary[i] in neighbours:
            neighbours[dictionary[i]] = []
    
    return neighbours
    

def highest_score_stepladder():

    word_length, dictionary, scores = read_dictionary_from_file()
    
    dictionary = sorted([w for w in dictionary if len(w) == word_length], key=lambda w: scores[w], reverse=True)
    
    neighbours = compute_neighbours_list(dictionary)

    highest_score = 0
    for w in dictionary:
        s_w = scores[w]
        if highest_score >= s_w ** 2:
            continue
        stack = [(w, w, [], -scores[w])]
        s_append = stack.append
        s_pop = stack.pop
        
        while len(stack) > 0:
            bottom, top, old_ladder, score = s_pop()
            score += scores[top] + scores[bottom]
            
            ladder = old_ladder[:]
            ladder.append(bottom)
            ladder.append(top)
            if score > highest_score:
                highest_score = score
            bottom_neighbours = [w for w in neighbours[bottom]
                                    if (not w in ladder)
                                    and scores[w] < scores[bottom]]
            top_neighbours = [w for w in neighbours[top]
                                if (not w in ladder)
                                and scores[w] < scores[top]]
            for wb in bottom_neighbours:
                for wt in top_neighbours:
                    s_wt = scores[wt]
                    s_wb = scores[wb]
                    if wb != wt and score + s_wb * (s_wb + 1) / 2 + s_wt * (s_wt + 1) / 2 > highest_score:  # Upper bound on possible score
                        s_append((wb, wt, ladder, score))

    return highest_score 

if __name__ == '__main__':
    highest_score = highest_score_stepladder()
    print highest_score
